#获取当前系统时间
def sysTime(): #获取系统时间
    import time
    return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
def write_to_log(info):
    #路径是以源头文件为起点
    pro_path=getProjectPath()
    print(pro_path)
    f=open(pro_path+"\log\log.txt",'a')  #a是追加写入信息到文本中
    f.write(sysTime())
    f.write(" ")
    f.write(info)
    f.write("\n")
    f.close()
def getProjectPath(): #获取项目的根目录的路径
    import os
    print(os.path.dirname(__file__))  # C:/Users/Administrator/pycharmProjects/dbshop1/main
    curPath = os.path.abspath(os.path.dirname(__file__))  # 获取当前文件的所在目录的绝对路径
    # print(curPath)  # C:\Users\Administrator\pycharmProjects\dbshop1\main
    # 将当前文件的所在目录的绝对路径进行分离,分离成('C:\\Users\\Administrator\pycharmProjects\\dbshop1', 'main')  和main,存到元组中
    # print(os.path.split(curPath))  # ('C:\\Users\\Administrator\\pycharmProjects\\dbshop1', 'main')
    rootPath = os.path.split(curPath)[0]  # [0]表示元组中的为一个元素
    # print(rootPath)
    return  rootPath


